convert php array to javascript array

66

convert php array to javascript array -

<?php
    $vegetables = ['apple', 'strawberry', 'banana'];
?>

<script>
var arr = "<?php echo implode(",", $vegetables); ?>".split(",");
console.log(arr); //["apple", "strawberry", "banana"]
Vue.component('#app7', {
    props: arr,
    template: '<li>{{ item.text }}</li>'
})

</script>

copy php array to javascript -

var js_array = [<?php echo '"'.implode('","', $php_array).'"' ?>];

convert a php array into a javascript array -

var js_array = [<?php echo '"'.implode('","',  $disabledDaysRange ).'"' ?>];

Comments

Submit
0 Comments